<?php
/* SVN FILE: $Id: giga_app_helper.php 1059 2012-05-21 13:26:17Z shrey $ */
/**
 * Short description for file.
 *
 * This file is application-wide helper file. You can put all
 * application-wide helper-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) :  Rapid Development Framework <http://www.cakephp.org/>
 * Copyright 2005-2008, Cake Software Foundation, Inc.
 *								1785 E. Sahara Avenue, Suite 490-204
 *								Las Vegas, Nevada 89104
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright		Copyright 2005-2008, Cake Software Foundation, Inc.
 * @link				http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
 * @package			cake
 * @subpackage		cake.cake
 * @since			CakePHP(tm) v 0.2.9
 * @version			$Revision: 1059 $
 * @modifiedby		$LastChangedBy: shrey $
 * @lastmodified	$Date: 2012-05-21 18:56:17 +0530 (Mon, 21 May 2012) $
 * @license			http://www.opensource.org/licenses/mit-license.php The MIT License
 */
/**
 * This is a placeholder class.
 * Create the same file in app/app_helper.php
 *
 * Add your application-wide methods in the class below, your helpers
 * will inherit them.
 *
 * @package		cake
 * @subpackage	cake.cake
 */
class GigaAppHelper extends Helper {
	
	/**
	 * This functions adds jQuery UI library to your view. 
	 * Dont worry about double calling to this function, it'll also make sure jQuery UI library is included only once
	 *
	 */
	function addJUI()
	{
		if(is_a($this,'HtmlHelper'))
		{
			$html = $this;
		}else
		{
			$this->initHelper('Html');
			$html = $this->Html;
		}
		if(is_a($this,'JavascriptHelper'))
		{
			$javascript = $this;
		}else
		{
			$this->initHelper('Javascript');
			$javascript = $this->Javascript;
		}
		$theme = Configure::read('juiTheme');
		$view =& ClassRegistry::getObject('view');
		$javascript->link('/cms/js/jquery.ui.1.8.2.js',false);
		if($theme != 'app')
		{
			$cssFile = '/cms/css/jquery-ui-'.$theme.'.css';
		}
		else
		{
			$cssFile ='/cms/css/jquery-ui-default.css';
		}
		$html->css($cssFile,null,array(),false);
	}

	function initHelper($helper = null)
	{
		$helperName = array_pop(explode('.',$helper));
		if(!isset($this->{$helperName}) || is_object($this->{$helperName}) || is_a($this->{$helperName},$helperName.'Helper'))
		{
			$View = $this->getView();
			$HelperInstance = null;
			$helperVarName = Inflector::variable($helperName);
			if(isset($View->loaded[$helperName]))
			{
				$HelperInstance = $View->loaded[$helperName];
			}else if(isset($View->loaded[$helperVarName]))
			{
				$HelperInstance = $View->loaded[$helperVarName];
			}
			
			if(!is_object($HelperInstance))
			{
				$View->_loadHelpers($View->loaded,(array)$helper);
				$HelperInstance = $View->loaded[$helperName];
			}
			$this->{$helperName} = $HelperInstance;
		}
	}

	function addJqBlock($block)
	{
		ClassRegistry::getObject('view')->addJqBlock($block);
	}
	
	function webroot($file,$full=false)
	{
		$url = parent::webroot($file);
		if($full==true)
		{
			$url  = FULL_BASE_URL.$url;
		}
		return $url;
	}
	
	function getView()
	{
		return ClassRegistry::getObject('view');
	}
	
	function getModel($plugin = false, $model = false)
	{
		if(!$plugin && !$model)
			return ClassRegistry::getObject($this->model());
			
		return parent::getModel($plugin, $model);
	}


}
?>